'''
python程序，读取一个文件，
统计文件某个单词次数，并输出结果，
文件名为text.txt.
Python is a programming language .
Python is easy to learn.
Python is widely used.
统计单词次数Python 
'''

with open('./file/text.txt','r',encoding='UTF-8') as f :
    text_str = f.read()
    print(text_str.count('Python'))

print('===========')


'''
练习2
使用with语句和read（）方式一次性读取内容
用split('\n')分割行并统计行数
'''
with open('./file/text.txt','r',encoding='UTF-8') as f :
    text = f.read()
    #print(text)
    text_list = text.split('\n')
    count = 0
    for i in text_list:
        count += 1
        print(i)
    print(f'总行数：{count}')



